﻿#include "LoginScene.h"
#include "../MirSounds/SoundManager.h"
#include "../MirGraphics/MLibrary.h"
#include "../Settings.h"
#include "../../Shared/Globals.h"
#include "../MirNetwork/Network.h"
#include "../../Shared/Language.h"
#include "../../Shared/Enums.h"
#include "../../Shared/ClientPackets.h"
#include "../Forms/Client.CMain.h"

using namespace Client::MirControls;
using namespace Client::MirGraphics;
using namespace Client::MirNetwork;
using namespace Client::MirSounds;
namespace S = ServerPackets;
namespace C = ClientPackets;

namespace Client::MirScenes
{

    LoginScene::LoginScene()
    {
        SoundManager::PlaySound(SoundList::IntroMusic, true);
        Disposing += [&] (o, e)
        {
            SoundManager::StopSound(SoundList::IntroMusic);
        };

        _background = new MirAnimatedControl();
        _background->setAnimated(false);
        _background->setAnimationCount(19);
        _background->setAnimationDelay(100);
        _background->setIndex(0);
        _background->setLibrary(Libraries::ChrSel);
        _background->setLoop(false);
        _background->setParent(this);

        _login = new LoginDialog();
        _login->setParent(_background);
        _login->setVisible(false);
        _login->AccountButton->Click += [&] (o, e)
        {
                _login->Hide();
                if (_ViewKey != nullptr && !_ViewKey->isDisposed())
                {
                    _ViewKey->Dispose();
                }
                _account = new NewAccountDialog();
                _account->setParent(_background);
                _account->Disposing->addListener([&] (o1, e1)
                {
                _login->Show();
                });
        };
        _login->PassButton->Click += [&] (o, e)
        {
                _login->Hide();
                if (_ViewKey != nullptr && !_ViewKey->isDisposed())
                {
                    _ViewKey->Dispose();
                }
                _password = new ChangePasswordDialog();
                _password->setParent(_background);
                _password->Disposing->addListener([&] (o1, e1)
                {
                _login->Show();
                });
        };

        _login->ViewKeyButton->Click += [&] (o, e)
        {
            if (_ViewKey != nullptr && !_ViewKey->isDisposed())
            {
                return;
            }
    
            _ViewKey = new InputKeyDialog(_login);
            _ViewKey->setParent(_background);
        }; //ADD

        Version = new MirLabel();
        Version->setAutoSize(true);
        Version->setBackColour(Color::FromArgb(200, 50, 50, 50));
        Version->setBorder(true);
        Version->setBorderColour(Color::Black);
        Point tempVar(5, Settings::ScreenHeight - 20);
        Version->setLocation(&tempVar);
        Version->setParent(_background);
        Version->setText(StringHelper::formatSimple("Build: {0}.{1}.{2}", Globals::ProductCodename, Globals::ProductVersion, Application::ProductVersion));

        TestLabel = new MirImageControl();
        TestLabel->setIndex(79);
        TestLabel->setLibrary(Libraries::Prguse);
        TestLabel->setParent(this);
        Point tempVar2(Settings::ScreenWidth - 116, 10);
        TestLabel->setLocation(&tempVar2);
        TestLabel->setVisible(Settings::getUseTestConfig());

        //ViolenceLabel = new MirImageControl
        //{
        //    Index = 89,
        //    Library = Libraries.Prguse,
        //    Parent = this,
        //    Location = new Point(471, 10)
        //};

        //MinorLabel = new MirImageControl
        //{
        //    Index = 87,
        //    Library = Libraries.Prguse,
        //    Parent = this,
        //    Location = new Point(578, 10)
        //};

        //YouthLabel = new MirImageControl
        //{
        //    Index = 88,
        //    Library = Libraries.Prguse,
        //    Parent = this,
        //    Location = new Point(684, 10)
        //};

        _connectBox = new MirMessageBox("Attempting to connect to the server.", MirMessageBoxButtons::Cancel);
        _connectBox->CancelButton->Click += [&] (o, e)
        {
            Program::Form->Close();
        };
        Shown += [&] (sender, args)
        {
                Network::Connect();
                _connectBox->Show();
        };
    }

    void LoginScene::Process()
    {
        if (!Network::Connected && _connectBox->Label != nullptr)
        {
            _connectBox->Label->setText(std::string::Format(GameLanguage::AttemptingConnect,"\n\n", Network::ConnectAttempt));
        }
    }

    void LoginScene::ProcessPacket(Packet *p)
    {
        switch (p->getIndex())
        {
            case static_cast<short>(ServerPacketIds::Connected):
                Network::Connected = true;
                SendVersion();
                break;
            case static_cast<short>(ServerPacketIds::ClientVersion):
                ClientVersion(static_cast<S::ClientVersion*>(p));
                break;
            case static_cast<short>(ServerPacketIds::NewAccount):
                NewAccount(static_cast<S::NewAccount*>(p));
                break;
            case static_cast<short>(ServerPacketIds::ChangePassword):
                ChangePassword(static_cast<S::ChangePassword*>(p));
                break;
            case static_cast<short>(ServerPacketIds::ChangePasswordBanned):
                ChangePassword(static_cast<S::ChangePasswordBanned*>(p));
                break;
            case static_cast<short>(ServerPacketIds::Login):
                Login(static_cast<S::Login*>(p));
                break;
            case static_cast<short>(ServerPacketIds::LoginBanned):
                Login(static_cast<S::LoginBanned*>(p));
                break;
            case static_cast<short>(ServerPacketIds::LoginSuccess):
                Login(static_cast<S::LoginSuccess*>(p));
                break;
            default:
                MirScene::ProcessPacket(p);
                break;
        }
    }

    void LoginScene::SendVersion()
    {
        _connectBox->Label->setText("Sending Client Version.");

        C::ClientVersion *p = new C::ClientVersion();
        try
        {
            std::vector<unsigned char> sum;
//C# TO C++ CONVERTER NOTE: The following 'using' block is replaced by its C++ equivalent:
//ORIGINAL LINE: using (MD5 md5 = MD5.Create())
            {
                MD5 md5 = MD5::Create();
//C# TO C++ CONVERTER NOTE: The following 'using' block is replaced by its C++ equivalent:
//ORIGINAL LINE: using (FileStream stream = File.OpenRead(Application.ExecutablePath))
                {
                FileStream stream = File::OpenRead(Application::ExecutablePath);
                sum = md5.ComputeHash(stream);
                }
            }

            p->VersionHash = sum;
                Network::Enqueue(p);
        }
        catch (const std::runtime_error &ex)
        {
            if (Settings::LogErrors)
            {
                CMain::SaveError(ex.what());
            }
        }

//C# TO C++ CONVERTER TODO TASK: A 'delete p' statement was not added since p was passed to a method or constructor. Handle memory management manually.
    }

    void LoginScene::ClientVersion(S::ClientVersion *p)
    {
        switch (p->Result)
        {
            case 0:
                MirMessageBox::Show("Wrong version, please update your game.\nGame will now Close", true);

                Network::Disconnect();
                break;
            case 1:
                _connectBox->Dispose();
                _login->Show();
                break;
        }
    }

    void LoginScene::NewAccount(S::NewAccount *p)
    {
        _account->OKButton->setEnabled(true);
        switch (p->Result)
        {
            case 0:
                MirMessageBox::Show("Account creation is currently disabled.");
                _account->Dispose();
                break;
            case 1:
                MirMessageBox::Show("Your AccountID is not acceptable.");
                _account->AccountIDTextBox->SetFocus();
                break;
            case 2:
                MirMessageBox::Show("Your Password is not acceptable.");
                _account->Password1TextBox->SetFocus();
                break;
            case 3:
                MirMessageBox::Show("Your E-Mail Address is not acceptable.");
                _account->EMailTextBox->SetFocus();
                break;
            case 4:
                MirMessageBox::Show("Your User Name is not acceptable.");
                _account->UserNameTextBox->SetFocus();
                break;
            case 5:
                MirMessageBox::Show("Your Secret Question is not acceptable.");
                _account->QuestionTextBox->SetFocus();
                break;
            case 6:
                MirMessageBox::Show("Your Secret Answer is not acceptable.");
                _account->AnswerTextBox->SetFocus();
                break;
            case 7:
                MirMessageBox::Show("An Account with this ID already exists.");
                _account->AccountIDTextBox->setText("");
                _account->AccountIDTextBox->SetFocus();
                break;
            case 8:
                MirMessageBox::Show("Your account was created successfully.");
                _account->Dispose();
                break;
        }
    }

    void LoginScene::ChangePassword(S::ChangePassword *p)
    {
        _password->OKButton->setEnabled(true);

        switch (p->Result)
        {
            case 0:
                MirMessageBox::Show("Password Changing is currently disabled.");
                _password->Dispose();
                break;
            case 1:
                MirMessageBox::Show("Your AccountID is not acceptable.");
                _password->AccountIDTextBox->SetFocus();
                break;
            case 2:
                MirMessageBox::Show("The current Password is not acceptable.");
                _password->CurrentPasswordTextBox->SetFocus();
                break;
            case 3:
                MirMessageBox::Show("Your new Password is not acceptable.");
                _password->NewPassword1TextBox->SetFocus();
                break;
            case 4:
                MirMessageBox::Show(GameLanguage::NoAccountID);
                _password->AccountIDTextBox->SetFocus();
                break;
            case 5:
                MirMessageBox::Show(GameLanguage::IncorrectPasswordAccountID);
                _password->CurrentPasswordTextBox->SetFocus();
                _password->CurrentPasswordTextBox->setText("");
                break;
            case 6:
                MirMessageBox::Show("Your password was changed successfully.");
                _password->Dispose();
                break;
        }
    }

    void LoginScene::ChangePassword(S::ChangePasswordBanned *p)
    {
        _password->Dispose();

        TimeSpan d = p->ExpiryDate - CMain::getNow();
        MirMessageBox::Show(std::string::Format("This account is banned.\n\nReason: {0}\nExpiryDate: {1}\nDuration: {2:#,##0} Hours, {3} Minutes, {4} Seconds", p->Reason, p->ExpiryDate, std::floor(d.TotalHours), d.Minutes, d.Seconds));
    }

    void LoginScene::Login(S::Login *p)
    {
        _login->OKButton->setEnabled(true);
        switch (p->Result)
        {
            case 0:
                MirMessageBox::Show("Logging in is currently disabled.");
                _login->Clear();
                break;
            case 1:
                MirMessageBox::Show("Your AccountID is not acceptable.");
                _login->AccountIDTextBox->SetFocus();
                break;
            case 2:
                MirMessageBox::Show("Your Password is not acceptable.");
                _login->PasswordTextBox->SetFocus();
                break;
            case 3:
                MirMessageBox::Show(GameLanguage::NoAccountID);
                _login->PasswordTextBox->SetFocus();
                break;
            case 4:
                MirMessageBox::Show(GameLanguage::IncorrectPasswordAccountID);
                _login->PasswordTextBox->setText("");
                _login->PasswordTextBox->SetFocus();
                break;
        }
    }

    void LoginScene::Login(S::LoginBanned *p)
    {
        _login->OKButton->setEnabled(true);

        TimeSpan d = p->ExpiryDate - CMain::getNow();
        MirMessageBox::Show(std::string::Format("This account is banned.\n\nReason: {0}\nExpiryDate: {1}\nDuration: {2:#,##0} Hours, {3} Minutes, {4} Seconds", p->Reason, p->ExpiryDate, std::floor(d.TotalHours), d.Minutes, d.Seconds));
    }

    void LoginScene::Login(S::LoginSuccess *p)
    {
        setEnabled(false);
        _login->Dispose();
        if (_ViewKey != nullptr && !_ViewKey->isDisposed())
        {
            _ViewKey->Dispose();
        }

        SoundManager::PlaySound(SoundList::LoginEffect);
        _background->setAnimated(true);
        _background->AfterAnimation->addListener([&] (o, e)
        {
                Dispose();
                ActiveScene = new SelectScene(p->Characters);
        });
    }

    LoginScene::LoginDialog::LoginDialog()
    {
        setIndex(1084);
        setLibrary(Libraries::Prguse);
        Point tempVar((Settings::ScreenWidth - getSize()->Width) / 2, (Settings::ScreenHeight - getSize()->Height) / 2);
        setLocation(&tempVar);
        setPixelDetect(false);
        Size tempVar2(328, 220);
        setSize(&tempVar2);

        TitleLabel = new MirImageControl();
        TitleLabel->setIndex(30);
        TitleLabel->setLibrary(Libraries::Title);
        TitleLabel->setParent(this);
        Point tempVar3((getSize()->Width - TitleLabel->getSize()->Width) / 2, 12);
        TitleLabel->setLocation(&tempVar3);

        AccountIDLabel = new MirImageControl();
        AccountIDLabel->setIndex(31);
        AccountIDLabel->setLibrary(Libraries::Title);
        AccountIDLabel->setParent(this);
        Point tempVar4(52, 83);
        AccountIDLabel->setLocation(&tempVar4);

        PassLabel = new MirImageControl();
        PassLabel->setIndex(32);
        PassLabel->setLibrary(Libraries::Title);
        PassLabel->setParent(this);
        Point tempVar5(43, 105);
        PassLabel->setLocation(&tempVar5);

        OKButton = new MirButton();
        OKButton->setEnabled(false);
        Size tempVar6(42,42);
        OKButton->setSize(&tempVar6);
        OKButton->setHoverIndex(321);
        OKButton->setIndex(320);
        OKButton->setLibrary(Libraries::Title);
        Point tempVar7(227, 81);
        OKButton->setLocation(&tempVar7);
        OKButton->setParent(this);
        OKButton->setPressedIndex(322);
        OKButton->Click += [&] (o, e)
        {
            Login();
        };

        AccountButton = new MirButton();
        AccountButton->setHoverIndex(324);
        AccountButton->setIndex(323);
        AccountButton->setLibrary(Libraries::Title);
        Point tempVar8(60, 163);
        AccountButton->setLocation(&tempVar8);
        AccountButton->setParent(this);
        AccountButton->setPressedIndex(325);

        PassButton = new MirButton();
        PassButton->setHoverIndex(327);
        PassButton->setIndex(326);
        PassButton->setLibrary(Libraries::Title);
        Point tempVar9(166, 163);
        PassButton->setLocation(&tempVar9);
        PassButton->setParent(this);
        PassButton->setPressedIndex(328);

        ViewKeyButton = new MirButton();
        ViewKeyButton->setHoverIndex(333);
        ViewKeyButton->setIndex(332);
        ViewKeyButton->setLibrary(Libraries::Title);
        Point tempVar10(60, 189);
        ViewKeyButton->setLocation(&tempVar10);
        ViewKeyButton->setParent(this);
        ViewKeyButton->setPressedIndex(334);

        CloseButton = new MirButton();
        CloseButton->setHoverIndex(330);
        CloseButton->setIndex(329);
        CloseButton->setLibrary(Libraries::Title);
        Point tempVar11(166, 189);
        CloseButton->setLocation(&tempVar11);
        CloseButton->setParent(this);
        CloseButton->setPressedIndex(331);
        CloseButton->Click += [&] (o, e)
        {
            Program::Form->Close();
        };

        PasswordTextBox = new MirTextBox();
        Point tempVar12(85, 108);
        PasswordTextBox->setLocation(&tempVar12);
        PasswordTextBox->setParent(this);
        PasswordTextBox->setPassword(true);
        Size tempVar13(136, 15);
        PasswordTextBox->setSize(&tempVar13);
        PasswordTextBox->setMaxLength(Globals::MaxPasswordLength);

        PasswordTextBox->TextBox->TextChanged += PasswordTextBox_TextChanged;
        PasswordTextBox->TextBox->KeyPress += TextBox_KeyPress;
        PasswordTextBox->setText(Settings::Password);

        AccountIDTextBox = new MirTextBox();
        Point tempVar14(85, 85);
        AccountIDTextBox->setLocation(&tempVar14);
        AccountIDTextBox->setParent(this);
        Size tempVar15(136, 15);
        AccountIDTextBox->setSize(&tempVar15);
        AccountIDTextBox->setMaxLength(Globals::MaxAccountIDLength);

        AccountIDTextBox->TextBox->TextChanged += AccountIDTextBox_TextChanged;
        AccountIDTextBox->TextBox->KeyPress += TextBox_KeyPress;
        AccountIDTextBox->setText(Settings::AccountID);

    }

    void LoginScene::LoginDialog::AccountIDTextBox_TextChanged(std::any sender, EventArgs *e)
    {
        Regex *reg = new Regex(R"(^[A-Za-z0-9]{)" + std::to_string(Globals::MinAccountIDLength) + "," + std::to_string(Globals::MaxAccountIDLength) + "}$");

        if (AccountIDTextBox->getText().empty() || !reg->IsMatch(AccountIDTextBox->TextBox->Text))
        {
            _accountIDValid = false;
            AccountIDTextBox->setBorder(!AccountIDTextBox->getText().empty());
            AccountIDTextBox->setBorderColour(Color::Red);
        }
        else
        {
            _accountIDValid = true;
            AccountIDTextBox->setBorder(true);
            AccountIDTextBox->setBorderColour(Color::Green);
        }

        delete reg;
    }

    void LoginScene::LoginDialog::PasswordTextBox_TextChanged(std::any sender, EventArgs *e)
    {
        Regex *reg = new Regex(R"(^[A-Za-z0-9]{)" + std::to_string(Globals::MinPasswordLength) + "," + std::to_string(Globals::MaxPasswordLength) + "}$");

        if (PasswordTextBox->TextBox->Text.empty() || !reg->IsMatch(PasswordTextBox->TextBox->Text))
        {
            _passwordValid = false;
            PasswordTextBox->setBorder(!PasswordTextBox->TextBox->Text.empty());
            PasswordTextBox->setBorderColour(Color::Red);
        }
        else
        {
            _passwordValid = true;
            PasswordTextBox->setBorder(true);
            PasswordTextBox->setBorderColour(Color::Green);
        }

        RefreshLoginButton();

        delete reg;
    }

    void LoginScene::LoginDialog::TextBox_KeyPress(std::any sender, KeyPressEventArgs *e)
    {
        if (!sender.has_value() || e->KeyChar != static_cast<char>(Keys->Enter))
        {
            return;
        }

        e->Handled = true;

        if (!_accountIDValid)
        {
            AccountIDTextBox->SetFocus();
            return;
        }
        if (!_passwordValid)
        {
            PasswordTextBox->SetFocus();
            return;
        }

        if (OKButton->getEnabled())
        {
            OKButton->InvokeMouseClick(nullptr);
        }
    }

    void LoginScene::LoginDialog::RefreshLoginButton()
    {
        OKButton->setEnabled(_accountIDValid && _passwordValid);
    }

    void LoginScene::LoginDialog::Login()
    {
        OKButton->setEnabled(false);
        C::Login *tempVar = new C::Login();
        tempVar->AccountID = AccountIDTextBox->getText();
        tempVar->Password = PasswordTextBox->getText();
        Network::Enqueue(tempVar);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar' statement was not added since tempVar was passed to a method or constructor. Handle memory management manually.
    }

    void LoginScene::LoginDialog::Show()
    {
        if (getVisible())
        {
            return;
        }
        setVisible(true);
        AccountIDTextBox->SetFocus();

        if (Settings::Password != "" && Settings::AccountID != "")
        {
            Login();
        }
    }

    void LoginScene::LoginDialog::Clear()
    {
        AccountIDTextBox->setText("");
        PasswordTextBox->setText("");
    }

    void LoginScene::LoginDialog::Dispose(bool disposing)
    {
        if (disposing)
        {
            TitleLabel = nullptr;
            AccountIDLabel = nullptr;
            PassLabel = nullptr;
            AccountButton = nullptr;
            CloseButton = nullptr;
            OKButton = nullptr;
            PassButton = nullptr;
            AccountIDTextBox = nullptr;
            PasswordTextBox = nullptr;

        }

        MirImageControl::Dispose(disposing);
    }

    LoginScene::InputKeyDialog::InputKeyDialog(LoginDialog *loginDialog) : KeyEscButton(new MirButton();
            KeyEscButton->setText("Esc");
            KeyEscButton->setHoverIndex(301);
            KeyEscButton->setIndex(300);
            KeyEscButton->setLibrary(Libraries::Title);
            Point tempVar(12, 12);
            KeyEscButton->setLocation(&tempVar);
            KeyEscButton->setParent(this);
            KeyEscButton->setPressedIndex(302);
            KeyEscButton->setCenterText(true)), KeyDelButton(new MirButton();
            KeyDelButton->setText("Delete");
            KeyDelButton->setHoverIndex(304);
            KeyDelButton->setIndex(303);
            KeyDelButton->setLibrary(Libraries::Title);
            Point tempVar2(140, 76);
            KeyDelButton->setLocation(&tempVar2);
            KeyDelButton->setParent(this);
            KeyDelButton->setPressedIndex(305);
            KeyDelButton->setCenterText(true)), KeyRandButton(new MirButton();
            KeyRandButton->setText("Random");
            KeyRandButton->setHoverIndex(310);
            KeyRandButton->setIndex(309);
            KeyRandButton->setLibrary(Libraries::Title);
            Point tempVar3(76, 236);
            KeyRandButton->setLocation(&tempVar3);
            KeyRandButton->setParent(this);
            KeyRandButton->setPressedIndex(311);
            KeyRandButton->setCenterText(true)), KeyEnterButton(new MirButton();
            KeyEnterButton->setText("Enter");
            KeyEnterButton->setHoverIndex(307);
            KeyEnterButton->setIndex(306);
            KeyEnterButton->setLibrary(Libraries::Title);
            Point tempVar4(140, 236);
            KeyEnterButton->setLocation(&tempVar4);
            KeyEnterButton->setParent(this);
            KeyEnterButton->setPressedIndex(308);
            KeyEnterButton->setCenterText(true))
            {
        _loginDialog = loginDialog;

        setIndex(1080);
        setLibrary(Libraries::Prguse);
        Point tempVar5((Client::Settings::ScreenWidth - getSize()->Width) / 2 + 285, (Client::Settings::ScreenHeight - getSize()->Height) / 2 + 150);
        setLocation(&tempVar5);
        setVisible(true);

        KeyEscButton->Click += [&] (o, e)
        {
            Dispose();
        };

        KeyDelButton->Click += [&] (o, e)
        {
            SecureKeyDelete();
        };

        KeyEnterButton->Click += [&] (o, e)
        {
            KeyPressEventArgs *arg = new KeyPressEventArgs(static_cast<char>(Keys->Enter));
    
            _loginDialog->TextBox_KeyPress(o, arg);

//C# TO C++ CONVERTER TODO TASK: A 'delete arg' statement was not added since arg was passed to a method or constructor. Handle memory management manually.
        };

        KeyRandButton->Click += [&] (o, e)
        {
//C# TO C++ CONVERTER TODO TASK: The following lambda expression could not be converted:
            _letters = std::vector<char>((std::string(_letters.OrderBy(s => TangibleLambdaToken192)->ToArray()))->begin(), (std::string(_letters.OrderBy([&] (std::any s)
//C# TO C++ CONVERTER TODO TASK: The following lambda expression could not be converted:
            _numbers = std::vector<char>((std::string(_numbers.OrderBy(s => TangibleLambdaToken193)->ToArray()))->begin(), (std::string(_numbers.OrderBy([&] (std::any s)
    
            UpdateKeys();
        };

        UpdateKeys();
            }

    void LoginScene::InputKeyDialog::DisposeKeys()
    {
        for (auto button : _buttons)
        {
            if (button != nullptr && !button->isDisposed())
            {
                button->Dispose();
            }
        }
    }

    void LoginScene::InputKeyDialog::UpdateKeys()
    {
        DisposeKeys();

        for (int i = 0; i < _numbers.size(); i++)
        {
            char key = _numbers[i];

            MirButton *numButton = new MirButton();
            numButton->setHoverIndex(1082);
            numButton->setIndex(1081);
            Size tempVar(32, 30);
            numButton->setSize(&tempVar);
            numButton->setLibrary(Libraries::Prguse);
            Point tempVar2(12 + (i % 6 * 32), 44 + (i / 6 * 32));
            numButton->setLocation(&tempVar2);
            numButton->setParent(this);
            numButton->setPressedIndex(1083);
            numButton->setText(StringHelper::toString(_numbers[i]));
            numButton->setCenterText(true);
            numButton->Click += [&] (o, e)
            {
                SecureKeyPress(key);
            };

            _buttons.push_back(numButton);

//C# TO C++ CONVERTER TODO TASK: A 'delete numButton' statement was not added since numButton was passed to a method or constructor. Handle memory management manually.
        }

        for (int i = 0; i < _letters.size(); i++)
        {
            char key = _letters[i];

            MirButton *alphButton = new MirButton();
            alphButton->setHoverIndex(1082);
            alphButton->setIndex(1081);
            Size tempVar3(32, 30);
            alphButton->setSize(&tempVar3);
            alphButton->setLibrary(Libraries::Prguse);
            Point tempVar4(12 + (i % 6 * 32), 108 + (i / 6 * 32));
            alphButton->setLocation(&tempVar4);
            alphButton->setParent(this);
            alphButton->setPressedIndex(1083);
            alphButton->setText(StringHelper::toString(_letters[i]));
            alphButton->setCenterText(true);

            alphButton->Click += [&] (o, e)
            {
                SecureKeyPress(key);
            };

            _buttons.push_back(alphButton);

//C# TO C++ CONVERTER TODO TASK: A 'delete alphButton' statement was not added since alphButton was passed to a method or constructor. Handle memory management manually.
        }
    }

    void LoginScene::InputKeyDialog::SecureKeyPress(char chr)
    {
        MirTextBox *currentTextBox = GetFocussedTextBox();

        std::string keyToAdd = StringHelper::toString(chr);

        if (CMain::IsKeyLocked(Keys->CapsLock))
        {
            keyToAdd = StringHelper::toUpper(keyToAdd);
        }
        else
        {
            keyToAdd = StringHelper::toLower(keyToAdd);
        }

        currentTextBox->setText(currentTextBox->getText() + keyToAdd);
        currentTextBox->TextBox->SelectionLength = 0;
        currentTextBox->TextBox->SelectionStart = currentTextBox->getText().length();
    }

    void LoginScene::InputKeyDialog::SecureKeyDelete()
    {
        MirTextBox *currentTextBox = GetFocussedTextBox();

        if (currentTextBox->TextBox->SelectionLength > 0)
        {
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to the .NET String 'Remove' method unless assigning to the string instance:
            currentTextBox->setText(currentTextBox->getText().Remove(currentTextBox->TextBox->SelectionStart, currentTextBox->TextBox->SelectionLength));
        }
        else if (currentTextBox->getText().length() > 0)
        {
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to the .NET String 'Remove' method unless assigning to the string instance:
            currentTextBox->setText(currentTextBox->getText().Remove(currentTextBox->getText().length() - 1));
        }

        currentTextBox->TextBox->SelectionStart = currentTextBox->getText().length();
    }

    MirTextBox *LoginScene::InputKeyDialog::GetFocussedTextBox()
    {
        if (_loginDialog->AccountIDTextBox->TextBox->Focused)
        {
            return _loginDialog->AccountIDTextBox;
        }
        else
        {
            return _loginDialog->PasswordTextBox;
        }
    }

    void LoginScene::InputKeyDialog::Dispose(bool disposing)
    {
        MirImageControl::Dispose(disposing);

        DisposeKeys();
    }

    LoginScene::NewAccountDialog::NewAccountDialog()
    {
        setIndex(63);
        setLibrary(Libraries::Prguse);
        Size tempVar();
        setSize(&tempVar);
        Point tempVar2((Settings::ScreenWidth - getSize()->Width) / 2, (Settings::ScreenHeight - getSize()->Height) / 2);
        setLocation(&tempVar2);

        CancelButton = new MirButton();
        CancelButton->setHoverIndex(204);
        CancelButton->setIndex(203);
        CancelButton->setLibrary(Libraries::Title);
        Point tempVar3(409, 425);
        CancelButton->setLocation(&tempVar3);
        CancelButton->setParent(this);
        CancelButton->setPressedIndex(205);
        CancelButton->Click += [&] (o, e)
        {
            Dispose();
        };

        OKButton = new MirButton();
        OKButton->setEnabled(false);
        OKButton->setHoverIndex(201);
        OKButton->setIndex(200);
        OKButton->setLibrary(Libraries::Title);
        Point tempVar4(135, 425);
        OKButton->setLocation(&tempVar4);
        OKButton->setParent(this);
        OKButton->setPressedIndex(202);
        OKButton->Click += [&] (o, e)
        {
            CreateAccount();
        };


        AccountIDTextBox = new MirTextBox();
        AccountIDTextBox->setBorder(true);
        AccountIDTextBox->setBorderColour(Color::Gray);
        Point tempVar5(226, 103);
        AccountIDTextBox->setLocation(&tempVar5);
        AccountIDTextBox->setMaxLength(Globals::MaxAccountIDLength);
        AccountIDTextBox->setParent(this);
        Size tempVar6(136, 18);
        AccountIDTextBox->setSize(&tempVar6);
        AccountIDTextBox->SetFocus();
        AccountIDTextBox->TextBox->MaxLength = Globals::MaxAccountIDLength;
        AccountIDTextBox->TextBox->TextChanged += AccountIDTextBox_TextChanged;
        AccountIDTextBox->TextBox->GotFocus += AccountIDTextBox_GotFocus;

        Password1TextBox = new MirTextBox();
        Password1TextBox->setBorder(true);
        Password1TextBox->setBorderColour(Color::Gray);
        Point tempVar7(226, 129);
        Password1TextBox->setLocation(&tempVar7);
        Password1TextBox->setMaxLength(Globals::MaxPasswordLength);
        Password1TextBox->setParent(this);
        Password1TextBox->setPassword(true);
        Size tempVar8(136, 18);
        Password1TextBox->setSize(&tempVar8);
        Password1TextBox->TextBox = {MaxLength = Globals::MaxPasswordLength};
        Password1TextBox->TextBox->TextChanged += Password1TextBox_TextChanged;
        Password1TextBox->TextBox->GotFocus += PasswordTextBox_GotFocus;

        Password2TextBox = new MirTextBox();
        Password2TextBox->setBorder(true);
        Password2TextBox->setBorderColour(Color::Gray);
        Point tempVar9(226, 155);
        Password2TextBox->setLocation(&tempVar9);
        Password2TextBox->setMaxLength(Globals::MaxPasswordLength);
        Password2TextBox->setParent(this);
        Password2TextBox->setPassword(true);
        Size tempVar10(136, 18);
        Password2TextBox->setSize(&tempVar10);
        Password2TextBox->TextBox = {MaxLength = Globals::MaxPasswordLength};
        Password2TextBox->TextBox->TextChanged += Password2TextBox_TextChanged;
        Password2TextBox->TextBox->GotFocus += PasswordTextBox_GotFocus;

        UserNameTextBox = new MirTextBox();
        UserNameTextBox->setBorder(true);
        UserNameTextBox->setBorderColour(Color::Gray);
        Point tempVar11(226, 189);
        UserNameTextBox->setLocation(&tempVar11);
        UserNameTextBox->setMaxLength(20);
        UserNameTextBox->setParent(this);
        Size tempVar12(136, 18);
        UserNameTextBox->setSize(&tempVar12);
        UserNameTextBox->TextBox = {MaxLength = 20};
        UserNameTextBox->TextBox->TextChanged += UserNameTextBox_TextChanged;
        UserNameTextBox->TextBox->GotFocus += UserNameTextBox_GotFocus;


        BirthDateTextBox = new MirTextBox();
        BirthDateTextBox->setBorder(true);
        BirthDateTextBox->setBorderColour(Color::Gray);
        Point tempVar13(226, 215);
        BirthDateTextBox->setLocation(&tempVar13);
        BirthDateTextBox->setMaxLength(10);
        BirthDateTextBox->setParent(this);
        Size tempVar14(136, 18);
        BirthDateTextBox->setSize(&tempVar14);
        BirthDateTextBox->TextBox = {MaxLength = 10};
        BirthDateTextBox->TextBox->TextChanged += BirthDateTextBox_TextChanged;
        BirthDateTextBox->TextBox->GotFocus += BirthDateTextBox_GotFocus;

        QuestionTextBox = new MirTextBox();
        QuestionTextBox->setBorder(true);
        QuestionTextBox->setBorderColour(Color::Gray);
        Point tempVar15(226, 250);
        QuestionTextBox->setLocation(&tempVar15);
        QuestionTextBox->setMaxLength(30);
        QuestionTextBox->setParent(this);
        Size tempVar16(190, 18);
        QuestionTextBox->setSize(&tempVar16);
        QuestionTextBox->TextBox = {MaxLength = 30};
        QuestionTextBox->TextBox->TextChanged += QuestionTextBox_TextChanged;
        QuestionTextBox->TextBox->GotFocus += QuestionTextBox_GotFocus;

        AnswerTextBox = new MirTextBox();
        AnswerTextBox->setBorder(true);
        AnswerTextBox->setBorderColour(Color::Gray);
        Point tempVar17(226, 276);
        AnswerTextBox->setLocation(&tempVar17);
        AnswerTextBox->setMaxLength(30);
        AnswerTextBox->setParent(this);
        Size tempVar18(190, 18);
        AnswerTextBox->setSize(&tempVar18);
        AnswerTextBox->TextBox = {MaxLength = 30};
        AnswerTextBox->TextBox->TextChanged += AnswerTextBox_TextChanged;
        AnswerTextBox->TextBox->GotFocus += AnswerTextBox_GotFocus;

        EMailTextBox = new MirTextBox();
        EMailTextBox->setBorder(true);
        EMailTextBox->setBorderColour(Color::Gray);
        Point tempVar19(226, 311);
        EMailTextBox->setLocation(&tempVar19);
        EMailTextBox->setMaxLength(50);
        EMailTextBox->setParent(this);
        Size tempVar20(136, 18);
        EMailTextBox->setSize(&tempVar20);
        EMailTextBox->TextBox = {MaxLength = 50};
        EMailTextBox->TextBox->TextChanged += EMailTextBox_TextChanged;
        EMailTextBox->TextBox->GotFocus += EMailTextBox_GotFocus;


        Description = new MirLabel();
        Description->setBorder(true);
        Description->setBorderColour(Color::Gray);
        Point tempVar21(15, 340);
        Description->setLocation(&tempVar21);
        Description->setParent(this);
        Size tempVar22(300, 70);
        Description->setSize(&tempVar22);
        Description->setVisible(false);

    }

    void LoginScene::NewAccountDialog::AccountIDTextBox_TextChanged(std::any sender, EventArgs *e)
    {
        Regex *reg = new Regex(R"(^[A-Za-z0-9]{)" + std::to_string(Globals::MinAccountIDLength) + "," + std::to_string(Globals::MaxAccountIDLength) + "}$");

        if (AccountIDTextBox->getText().empty() || !reg->IsMatch(AccountIDTextBox->getText()))
        {
            _accountIDValid = false;
            AccountIDTextBox->setBorderColour(Color::Red);
        }
        else
        {
            _accountIDValid = true;
            AccountIDTextBox->setBorderColour(Color::Green);
        }
        RefreshConfirmButton();

        delete reg;
    }

    void LoginScene::NewAccountDialog::Password1TextBox_TextChanged(std::any sender, EventArgs *e)
    {
        Regex *reg = new Regex(R"(^[A-Za-z0-9]{)" + std::to_string(Globals::MinPasswordLength) + "," + std::to_string(Globals::MaxPasswordLength) + "}$");

        if (Password1TextBox->getText().empty() || !reg->IsMatch(Password1TextBox->getText()))
        {
            _password1Valid = false;
            Password1TextBox->setBorderColour(Color::Red);
        }
        else
        {
            _password1Valid = true;
            Password1TextBox->setBorderColour(Color::Green);
        }
        Password2TextBox_TextChanged(sender, e);

        delete reg;
    }

    void LoginScene::NewAccountDialog::Password2TextBox_TextChanged(std::any sender, EventArgs *e)
    {
        Regex *reg = new Regex(R"(^[A-Za-z0-9]{)" + std::to_string(Globals::MinPasswordLength) + "," + std::to_string(Globals::MaxPasswordLength) + "}$");

        if (Password2TextBox->getText().empty() || !reg->IsMatch(Password2TextBox->getText()) || Password1TextBox->getText() != Password2TextBox->getText())
        {
            _password2Valid = false;
            Password2TextBox->setBorderColour(Color::Red);
        }
        else
        {
            _password2Valid = true;
            Password2TextBox->setBorderColour(Color::Green);
        }
        RefreshConfirmButton();

        delete reg;
    }

    void LoginScene::NewAccountDialog::EMailTextBox_TextChanged(std::any sender, EventArgs *e)
    {
        Regex *reg = new Regex(R"(\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)");
        if (EMailTextBox->getText().empty())
        {
            _eMailValid = true;
            EMailTextBox->setBorderColour(Color::Gray);
        }
        else if (!reg->IsMatch(EMailTextBox->getText()) || EMailTextBox->getText().length() > 50)
        {
            _eMailValid = false;
            EMailTextBox->setBorderColour(Color::Red);
        }
        else
        {
            _eMailValid = true;
            EMailTextBox->setBorderColour(Color::Green);
        }
        RefreshConfirmButton();

        delete reg;
    }

    void LoginScene::NewAccountDialog::UserNameTextBox_TextChanged(std::any sender, EventArgs *e)
    {
        if (UserNameTextBox->getText().empty())
        {
            _userNameValid = true;
            UserNameTextBox->setBorderColour(Color::Gray);
        }
        else if (UserNameTextBox->getText().length() > 20)
        {
            _userNameValid = false;
            UserNameTextBox->setBorderColour(Color::Red);
        }
        else
        {
            _userNameValid = true;
            UserNameTextBox->setBorderColour(Color::Green);
        }
        RefreshConfirmButton();
    }

    void LoginScene::NewAccountDialog::BirthDateTextBox_TextChanged(std::any sender, EventArgs *e)
    {
        DateTime dateTime;
        if (BirthDateTextBox->getText().empty())
        {
            _birthDateValid = true;
            BirthDateTextBox->setBorderColour(Color::Gray);
        }
        else if (!DateTime::TryParse(BirthDateTextBox->getText(), dateTime) || BirthDateTextBox->getText().length() > 10)
        {
            _birthDateValid = false;
            BirthDateTextBox->setBorderColour(Color::Red);
        }
        else
        {
            _birthDateValid = true;
            BirthDateTextBox->setBorderColour(Color::Green);
        }
        RefreshConfirmButton();
    }

    void LoginScene::NewAccountDialog::QuestionTextBox_TextChanged(std::any sender, EventArgs *e)
    {
        if (QuestionTextBox->getText().empty())
        {
            _questionValid = true;
            QuestionTextBox->setBorderColour(Color::Gray);
        }
        else if (QuestionTextBox->getText().length() > 30)
        {
            _questionValid = false;
            QuestionTextBox->setBorderColour(Color::Red);
        }
        else
        {
            _questionValid = true;
            QuestionTextBox->setBorderColour(Color::Green);
        }
        RefreshConfirmButton();
    }

    void LoginScene::NewAccountDialog::AnswerTextBox_TextChanged(std::any sender, EventArgs *e)
    {
        if (AnswerTextBox->getText().empty())
        {
            _answerValid = true;
            AnswerTextBox->setBorderColour(Color::Gray);
        }
        else if (AnswerTextBox->getText().length() > 30)
        {
            _answerValid = false;
            AnswerTextBox->setBorderColour(Color::Red);
        }
        else
        {
            _answerValid = true;
            AnswerTextBox->setBorderColour(Color::Green);
        }
        RefreshConfirmButton();
    }

    void LoginScene::NewAccountDialog::AccountIDTextBox_GotFocus(std::any sender, EventArgs *e)
    {
        Description->setVisible(true);
        Description->setText(" Description: Account ID.\n Accepted characters: a-z A-Z 0-9.\n Length: between " + std::to_string(Globals::MinAccountIDLength) + " and " + std::to_string(Globals::MaxAccountIDLength) + " characters.");
    }

    void LoginScene::NewAccountDialog::PasswordTextBox_GotFocus(std::any sender, EventArgs *e)
    {
        Description->setVisible(true);
        Description->setText(" Description: Password.\n Accepted characters: a-z A-Z 0-9.\n Length: between " + std::to_string(Globals::MinPasswordLength) + " and " + std::to_string(Globals::MaxPasswordLength) + " characters.");
    }

    void LoginScene::NewAccountDialog::EMailTextBox_GotFocus(std::any sender, EventArgs *e)
    {
        Description->setVisible(true);
        Description->setText(" Description: E-Mail Address.\n Format: Example@Example.Com.\n Max Length: 50 characters.\n Optional Field.");
    }

    void LoginScene::NewAccountDialog::UserNameTextBox_GotFocus(std::any sender, EventArgs *e)
    {
        Description->setVisible(true);
        Description->setText(" Description: User Name.\n Accepted characters:All.\n Length: between 0 and 20 characters.\n Optional Field.");
    }

    void LoginScene::NewAccountDialog::BirthDateTextBox_GotFocus(std::any sender, EventArgs *e)
    {
        Description->setVisible(true);
        Description->setText(StringHelper::formatSimple(" Description: Birth Date.\n Format: {0}.\n Length: 10 characters.\n Optional Field.", StringHelper::toUpper(Thread::CurrentThread->CurrentCulture->DateTimeFormat->ShortDatePattern)));
    }

    void LoginScene::NewAccountDialog::QuestionTextBox_GotFocus(std::any sender, EventArgs *e)
    {
        Description->setVisible(true);
        Description->setText(" Description: Secret Question.\n Accepted characters: All.\n Length: between 0 and 30 characters.\n Optional Field.");
    }

    void LoginScene::NewAccountDialog::AnswerTextBox_GotFocus(std::any sender, EventArgs *e)
    {
        Description->setVisible(true);
        Description->setText(" Description: Secret Answer.\n Accepted characters: All.\n Length: between 0 and 30 characters.\n Optional Field.");
    }

    void LoginScene::NewAccountDialog::RefreshConfirmButton()
    {
        OKButton->setEnabled(_accountIDValid && _password1Valid && _password2Valid && _eMailValid && _userNameValid && _birthDateValid && _questionValid && _answerValid);
    }

    void LoginScene::NewAccountDialog::CreateAccount()
    {
        OKButton->setEnabled(false);

        C::NewAccount *tempVar = new C::NewAccount();
        tempVar->AccountID = AccountIDTextBox->getText();
        tempVar->Password = Password1TextBox->getText();
        tempVar->EMailAddress = EMailTextBox->getText();
        tempVar->BirthDate = !BirthDateTextBox->getText().empty() ? DateTime::Parse(BirthDateTextBox->getText()) : DateTime::MinValue;
        tempVar->UserName = UserNameTextBox->getText();
        tempVar->SecretQuestion = QuestionTextBox->getText();
        tempVar->SecretAnswer = AnswerTextBox->getText();
        Network::Enqueue(tempVar);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar' statement was not added since tempVar was passed to a method or constructor. Handle memory management manually.
    }

    void LoginScene::NewAccountDialog::Show()
    {
        if (getVisible())
        {
            return;
        }
        setVisible(true);
        AccountIDTextBox->SetFocus();
    }

    void LoginScene::NewAccountDialog::Dispose(bool disposing)
    {
        if (disposing)
        {
            OKButton = nullptr;
            CancelButton = nullptr;

            AccountIDTextBox = nullptr;
            Password1TextBox = nullptr;
            Password2TextBox = nullptr;
            EMailTextBox = nullptr;
            UserNameTextBox = nullptr;
            BirthDateTextBox = nullptr;
            QuestionTextBox = nullptr;
            AnswerTextBox = nullptr;

            Description = nullptr;

        }

        MirImageControl::Dispose(disposing);
    }

    LoginScene::ChangePasswordDialog::ChangePasswordDialog() : OKButton(new MirButton();
            OKButton->setEnabled(false);
            OKButton->setHoverIndex(108);
            OKButton->setIndex(107);
            OKButton->setLibrary(Libraries::Title);
            Point tempVar(80, 236);
            OKButton->setLocation(&tempVar);
            OKButton->setParent(this);
            OKButton->setPressedIndex(109)), CancelButton(new MirButton();
            CancelButton->setHoverIndex(111);
            CancelButton->setIndex(110);
            CancelButton->setLibrary(Libraries::Title);
            Point tempVar2(222, 236);
            CancelButton->setLocation(&tempVar2);
            CancelButton->setParent(this);
            CancelButton->setPressedIndex(112)), AccountIDTextBox(new MirTextBox();
            AccountIDTextBox->setBorder(true);
            AccountIDTextBox->setBorderColour(Color::Gray);
            Point tempVar3(178, 75);
            AccountIDTextBox->setLocation(&tempVar3);
            AccountIDTextBox->setMaxLength(Globals::MaxAccountIDLength);
            AccountIDTextBox->setParent(this);
            Size tempVar4(136, 18);
            AccountIDTextBox->setSize(&tempVar4)), CurrentPasswordTextBox(new MirTextBox();
            CurrentPasswordTextBox->setBorder(true);
            CurrentPasswordTextBox->setBorderColour(Color::Gray);
            Point tempVar5(178, 113);
            CurrentPasswordTextBox->setLocation(&tempVar5);
            CurrentPasswordTextBox->setMaxLength(Globals::MaxPasswordLength);
            CurrentPasswordTextBox->setParent(this);
            CurrentPasswordTextBox->setPassword(true);
            Size tempVar6(136, 18);
            CurrentPasswordTextBox->setSize(&tempVar6);
            CurrentPasswordTextBox->TextBox = {MaxLength = Globals::MaxPasswordLength}), NewPassword1TextBox(new MirTextBox();
            NewPassword1TextBox->setBorder(true);
            NewPassword1TextBox->setBorderColour(Color::Gray);
            Point tempVar7(178, 151);
            NewPassword1TextBox->setLocation(&tempVar7);
            NewPassword1TextBox->setMaxLength(Globals::MaxPasswordLength);
            NewPassword1TextBox->setParent(this);
            NewPassword1TextBox->setPassword(true);
            Size tempVar8(136, 18);
            NewPassword1TextBox->setSize(&tempVar8);
            NewPassword1TextBox->TextBox = {MaxLength = Globals::MaxPasswordLength}), NewPassword2TextBox(new MirTextBox();
            NewPassword2TextBox->setBorder(true);
            NewPassword2TextBox->setBorderColour(Color::Gray);
            Point tempVar9(178, 188);
            NewPassword2TextBox->setLocation(&tempVar9);
            NewPassword2TextBox->setMaxLength(Globals::MaxPasswordLength);
            NewPassword2TextBox->setParent(this);
            NewPassword2TextBox->setPassword(true);
            Size tempVar10(136, 18);
            NewPassword2TextBox->setSize(&tempVar10);
            NewPassword2TextBox->TextBox = {MaxLength = Globals::MaxPasswordLength})
            {
        setIndex(50);
        setLibrary(Libraries::Prguse);
        Point tempVar11((Settings::ScreenWidth - getSize()->Width) / 2, (Settings::ScreenHeight - getSize()->Height) / 2);
        setLocation(&tempVar11);

        CancelButton->Click += [&] (o, e)
        {
            Dispose();
        };

        OKButton->Click += [&] (o, e)
        {
            ChangePassword();
        };


        AccountIDTextBox->SetFocus();
        AccountIDTextBox->TextBox->MaxLength = Globals::MaxAccountIDLength;
        AccountIDTextBox->TextBox->TextChanged += AccountIDTextBox_TextChanged;

        CurrentPasswordTextBox->TextBox->TextChanged += CurrentPasswordTextBox_TextChanged;

        NewPassword1TextBox->TextBox->TextChanged += NewPassword1TextBox_TextChanged;

        NewPassword2TextBox->TextBox->TextChanged += NewPassword2TextBox_TextChanged;

            }

    void LoginScene::ChangePasswordDialog::RefreshConfirmButton()
    {
        OKButton->setEnabled(_accountIDValid && _currentPasswordValid && _newPassword1Valid && _newPassword2Valid);
    }

    void LoginScene::ChangePasswordDialog::AccountIDTextBox_TextChanged(std::any sender, EventArgs *e)
    {
        Regex *reg = new Regex(R"(^[A-Za-z0-9]{)" + std::to_string(Globals::MinAccountIDLength) + "," + std::to_string(Globals::MaxAccountIDLength) + "}$");

        if (AccountIDTextBox->getText().empty() || !reg->IsMatch(AccountIDTextBox->getText()))
        {
            _accountIDValid = false;
            AccountIDTextBox->setBorderColour(Color::Red);
        }
        else
        {
            _accountIDValid = true;
            AccountIDTextBox->setBorderColour(Color::Green);
        }
        RefreshConfirmButton();

        delete reg;
    }

    void LoginScene::ChangePasswordDialog::CurrentPasswordTextBox_TextChanged(std::any sender, EventArgs *e)
    {
      Regex *reg = new Regex(R"(^[A-Za-z0-9]{)" + std::to_string(Globals::MinPasswordLength) + "," + std::to_string(Globals::MaxPasswordLength) + "}$");

        if (CurrentPasswordTextBox->getText().empty() || !reg->IsMatch(CurrentPasswordTextBox->getText()))
        {
            _currentPasswordValid = false;
            CurrentPasswordTextBox->setBorderColour(Color::Red);
        }
        else
        {
            _currentPasswordValid = true;
            CurrentPasswordTextBox->setBorderColour(Color::Green);
        }
        RefreshConfirmButton();

        delete reg;
    }

    void LoginScene::ChangePasswordDialog::NewPassword1TextBox_TextChanged(std::any sender, EventArgs *e)
    {
        Regex *reg = new Regex(R"(^[A-Za-z0-9]{)" + std::to_string(Globals::MinPasswordLength) + "," + std::to_string(Globals::MaxPasswordLength) + "}$");

        if (NewPassword1TextBox->getText().empty() || !reg->IsMatch(NewPassword1TextBox->getText()))
        {
            _newPassword1Valid = false;
            NewPassword1TextBox->setBorderColour(Color::Red);
        }
        else
        {
            _newPassword1Valid = true;
            NewPassword1TextBox->setBorderColour(Color::Green);
        }
        NewPassword2TextBox_TextChanged(sender, e);

        delete reg;
    }

    void LoginScene::ChangePasswordDialog::NewPassword2TextBox_TextChanged(std::any sender, EventArgs *e)
    {
        if (NewPassword1TextBox->getText() == NewPassword2TextBox->getText())
        {
            _newPassword2Valid = _newPassword1Valid;
            NewPassword2TextBox->setBorderColour(NewPassword1TextBox->getBorderColour());
        }
        else
        {
            _newPassword2Valid = false;
            NewPassword2TextBox->setBorderColour(Color::Red);
        }
        RefreshConfirmButton();
    }

    void LoginScene::ChangePasswordDialog::ChangePassword()
    {
        OKButton->setEnabled(false);

        C::ChangePassword *tempVar = new C::ChangePassword();
        tempVar->AccountID = AccountIDTextBox->getText();
        tempVar->CurrentPassword = CurrentPasswordTextBox->getText();
        tempVar->NewPassword = NewPassword1TextBox->getText();
        Network::Enqueue(tempVar);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar' statement was not added since tempVar was passed to a method or constructor. Handle memory management manually.
    }

    void LoginScene::ChangePasswordDialog::Show()
    {
        if (getVisible())
        {
            return;
        }
        setVisible(true);
        AccountIDTextBox->SetFocus();
    }

    void LoginScene::Dispose(bool disposing)
    {
        if (disposing)
        {
            _background = nullptr;
            Version = nullptr;

            _login = nullptr;
            _account = nullptr;
            _password = nullptr;

            _connectBox = nullptr;
        }

        MirScene::Dispose(disposing);
    }
}
